package com.shujia.map;

import com.shujia.common.IKUtil;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.types.Row;
import org.apache.flink.util.Collector;

import java.util.ArrayList;

public class WordCountFlatMapFuncation implements FlatMapFunction<Row, Tuple3<String, String, Integer>> {
    @Override
    public void flatMap(Row value, Collector<Tuple3<String, String, Integer>> out) throws Exception {
        String sentId = (String) value.getField(0);
        String text = (String) value.getField(1);

        //分词
        ArrayList<String> words = IKUtil.fit(text);
        for (String word : words) {

            Tuple3<String, String, Integer> result = new Tuple3<>(sentId, word, 1);
            out.collect(result);
        }
    }
}
